package com.yznote.cloudesk.logs;

import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;
import java.util.List;

public class PullConsumerTest {
    public static volatile boolean running = true;
    public static void main(String[] args) throws MQClientException {
        DefaultLitePullConsumer litePullConsumer = new DefaultLitePullConsumer("consumer1");
        litePullConsumer.setNamesrvAddr("101.35.255.8:9876");
        litePullConsumer.subscribe("messageToMysql", "*");
        //一次消费的数量
        litePullConsumer.setPullBatchSize(5);
        litePullConsumer.start();
        try {
            while (running) {
                List<MessageExt> messageExts = litePullConsumer.poll();
                System.out.printf("%s%n", messageExts);
            }
        } finally {
            litePullConsumer.shutdown();
        }
    }
}